<template>
  <div class="cotn_principal" :style="back" >
    <el-card class="cover" v-if="loginUser.id">
      <slide-verify :l="42"
                    :r="10"
                    :w="250"
                    :h="100"
                    slider-text="向右滑动"
                    @success="onSuccess"
                    @fail="onFail"
                    @refresh="onRefresh"
                    :imgs="imgs"
      ></slide-verify>
    </el-card>
    <div :style="back" style="width: 100vw;height: 85vh; position: fixed;left: 0; ">

    </div>





    <div style="margin: 50% 40% 0 0 ;" >
      <el-card style="width: 90vw; height: 22vh; margin-left: 10%;opacity: 0.9; border-radius: 22px">
          <div style="left: 0;margin-left: -25%;">
          <el-form label-width="80px" style="" :model="user" :rules="rules" ref="LoginForm">

            <el-form-item prop="username" style="border-radius: 30px">

              <el-input  v-model="user.username" style="width: 80vw" prefix-icon="el-icon-user"  placeholder="请输入账号"> </el-input>
            </el-form-item>

            <el-form-item prop="password">
              <el-input v-model="user.password" type="password" prefix-icon="el-icon-lock" style="width: 80vw" placeholder="请输入密码"></el-input>
            </el-form-item>

            <div style="display: flex; justify-content: center ;width: 70vw; margin-left: 25%">
              <el-button type="success" style="width: 20vw; height: 4vh" @click="login">登录</el-button>
              <el-button type="danger" style="width: 20vw; height: 4vh" @click="$router.push('/register')">注册
              </el-button>
            </div>
          </el-form>
        </div>
      </el-card>

    </div>


  </div>
</template>

<script>

import request from "@/utils/request";
import Cookies from "js-cookie"

export default {
  name: "Login.vue",
  data() {
    return {
      loginUser: {},
      user: {},
      imgs: ["https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202004%2F25%2F20200425173132_svsej.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1677749594&t=449ae4f66bcbe46ecd20b4abbb0c8f87",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202102%2F01%2F20210201195033_bdb69.jpg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1677749594&t=c1f6dbcb21b5eaa187fa6a1d7ebc97ad",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202006%2F07%2F20200607112138_gmhgt.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1677749716&t=e9f75a8f973c0a639eca7d265415c644",
      ],
      rules: {
        username: [
          {required: true, message: '请输入账号', trigger: 'blur'},
          {min: 3, max: 10, message: '长度在3到10之间', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 8, max: 16, message: '长度在8到16之间', trigger: 'blur'}
        ]
      },

      back: {
        backgroundImage: 'url(' + require('../assets/b.png') + ')',
        backgroundRepeat: 'no-repeat',
      },


    }
  },

  methods: {

    onSuccess() { //滑块验证通过之后触发的
      Cookies.set('user', JSON.stringify(this.loginUser))
      this.$router.push('/manage/home')
      this.$notify.success("登录成功")
    },
    onFail() {

    },
    onRefresh() {
      console.log('refresh')
    },

    login() {
      this.$refs['LoginForm'].validate((valid) => {
        if (valid) {
          request.post('/user/login', this.user).then(res => {
            if (res.code === '200') {
              this.loginUser = res.data
            } else {
              this.$notify.error(res.msg)
            }
          })
        }
      })

    },

  }
}

</script>

<style scoped>

/*rules表单校验提示*/


.cover {
  width: fit-content;
  background-color: white;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
}


* {
  text-align: center;
  margin: 0 auto;
  padding: 0;
  font-family: "Open Sans", sans-serif;
}

.cotn_principal {
  position: absolute;
  width: 100%;
  height: 100%;
  /*background: #cfd8dc;*/
  background-image: url("../assets/b.png");;
  background: -webkit-linear-gradient(
      -45deg,
      #cfd8dc 0%,
      #607d8b 100%,
      #b0bec5 100%
  );
  background: linear-gradient(
      135deg,
      #cfd8dc 0%,
      #607d8b 100%,
      #b0bec5 100%
  );
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cfd8dc', endColorstr='#b0bec5', GradientType=1);
}


</style>